package ualrcdg.shared.dto;

import java.util.Arrays;
import java.util.HashMap;

/**
 * Simple implementation of the "page" object. See CDG XML Specifications: Game Descriptor Files.
 */
public class Page
{
	private final String id;
	private final String name;
	private final String layoutId;
	private final String[] audioIds;
	private final String[] hapticIds;
	private final String[] entranceUpdateIds;
	private final String[] exitUpdateIds;
	private final HashMap< String, String > contents;
	
	/**
	 * Primary constructor
	 *
	 * @param id the id of the Page object to be created
	 * @param name the name of the Page object to be created
	 * @param audioIds the audioIds of the Page object to be created
	 * @param hapticIds the hapticIds of the Page object to be created
	 * @param updateIds the updateIds of the Page object to be created
	 * @param contents the contents of the Page object to be created
	 */
	public Page( String id, String name, String layoutId, String[] audioIds, String[] hapticIds, String[] entranceUpdateIds, String[] exitUpdateIds, HashMap< String, String > contents )
	{
		this.id = id;
		this.name = name;
		this.layoutId = layoutId;
		if( audioIds == null )
		{
			this.audioIds = null;
		}
		else
		{
			this.audioIds = Arrays.copyOf( audioIds, audioIds.length );			
		}
		if( hapticIds == null )
		{
			this.hapticIds = null;
		}
		else
		{
			this.hapticIds = Arrays.copyOf( hapticIds, hapticIds.length );			
		}
		if( entranceUpdateIds== null )
		{
			this.entranceUpdateIds = null;
		}
		else
		{
			this.entranceUpdateIds = Arrays.copyOf( entranceUpdateIds, entranceUpdateIds.length );			
		}
		if( exitUpdateIds== null )
		{
			this.exitUpdateIds = null;
		}
		else
		{
			this.exitUpdateIds = Arrays.copyOf( exitUpdateIds, exitUpdateIds.length );			
		}
		
		this.contents = new HashMap< String, String >( );
		for( String s : contents.keySet( ) )
		{
			this.contents.put( s, contents.get( s ) );
		}
		
		System.out.println( "Parsed: " + this.toString( ) );
	}

	/*
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString( )
	{
		return "Page [id=" + id + ", name=" + name + ", layoutId=" + layoutId + ", audioIds=" + Arrays.toString( audioIds ) + ", hapticIds=" + Arrays.toString( hapticIds ) + ", entranceUpdates=" + Arrays.toString( entranceUpdateIds )  + ", exitUpdates=" + Arrays.toString( exitUpdateIds ) + ", contents=" + contents + "]";
	}

	/**
	 * @return the id of this Page instance
	 */
	public String getId( )
	{
		return id;
	}

	/**
	 * @return the name of this Page instance
	 */
	public String getName( )
	{
		return name;
	}

	/**
	 * @return the layoutId of this Page instance
	 */
	public String getLayoutId( )
	{
		return layoutId;
	}
	
	/**
	 * @return the audioIds of this Page instance
	 */
	public String getAudioId( int index )
	{
		return audioIds[index];
	}
	
	/**
	 * @return the hapticIds of this Page instance
	 */
	public String getHapticId( int index )
	{
		return hapticIds[index];
	}
	
	/**
	 * @return the entranceUpdateIds of this Page instance
	 */
	public String[] getEntranceUpdateIDs( )
	{
		return entranceUpdateIds;
	}
	
	/**
	 * @return the exitUpdateIds of this Page instance
	 */
	public String[] getExitUpdateIDs( )
	{
		return exitUpdateIds;
	}
}
